<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>操作系统备考知识点录入系统</title>
  <style>
    :root {
      --bg-color: #f9fafb;
      --card-bg: #ffffff;
      --text-color: #111827;
      --primary: #10b981;
      --danger: #ef4444;
      --radius: 16px;
      --shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
      --transition: 0.2s ease;
    }

    * {
      box-sizing: border-box;
    }

    html, body {
      margin: 0;
      padding: 0;
      height: 100%;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      color: var(--text-color);
      background: var(--bg-color);
    }

    body {
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      z-index: 0;
    }

    .background {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: -1;
      background: radial-gradient(circle at 20% 30%, rgba(208, 241, 255, 0.5), transparent 60%),
                  radial-gradient(circle at 80% 70%, rgba(224, 212, 255, 0.5), transparent 60%),
                  linear-gradient(135deg, #f0f4ff, #fdfdff);
      background-size: cover;
      background-repeat: no-repeat;
    }

    .center-wrapper {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      max-width: 1200px;
      height: 100vh;
      padding: 40px 20px;
    }

    h1 {
      font-size: 2rem;
      font-weight: 600;
      margin-bottom: 20px;
      text-align: center;
    }

    .container {
      background: var(--card-bg);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 30px;
      width: 100%;
      max-width: 960px;
      transition: box-shadow var(--transition);
    }

    .container:hover {
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    }

    textarea {
      width: 100%;
      min-height: 160px;
      padding: 18px;
      font-size: 1.05rem;
      border: none;
      border-radius: var(--radius);
      background-color: #f3f4f6;
      resize: vertical;
      outline: none;
      margin-bottom: 25px;
      transition: background-color var(--transition);
    }

    textarea:focus {
      background-color: #fff;
      box-shadow: inset 0 0 0 2px var(--primary);
    }

    .button-group {
      display: flex;
      gap: 15px;
    }

    button {
      flex: 1;
      padding: 14px 20px;
      border: none;
      border-radius: var(--radius);
      font-size: 1rem;
      font-weight: 500;
      cursor: pointer;
      transition: background-color var(--transition), transform var(--transition);
    }

    button:hover {
      transform: translateY(-1px);
    }

    .add-btn {
      background-color: var(--primary);
      color: white;
    }

    .add-btn:hover {
      background-color: #0e9e6e;
    }

    .delete-btn {
      background-color: var(--danger);
      color: white;
    }

    .delete-btn:hover {
      background-color: #dc2626;
    }

    /* 顶部提示 Toast */
    .toast {
      position: fixed;
      top: 20px;
      left: 50%;
      transform: translateX(-50%) translateY(-40px);
      background: #333;
      color: white;
      padding: 14px 24px;
      border-radius: 12px;
      box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
      font-size: 1rem;
      font-weight: 500;
      opacity: 0;
      pointer-events: none;
      transition: all 0.4s ease;
      z-index: 9999;
    }

    .toast.show {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
      pointer-events: auto;
    }

    .toast.success {
      background-color: var(--primary);
    }

    .toast.error {
      background-color: var(--danger);
    }

    @media (max-width: 768px) {
      h1 {
        font-size: 1.6rem;
      }

      .container {
        padding: 20px;
      }

      textarea {
        font-size: 1rem;
        min-height: 180px;
      }

      button {
        font-size: 0.95rem;
        padding: 12px;
      }
    }

    @media (min-width: 1280px) {
      h1 {
        font-size: 2.4rem;
      }

      textarea {
        font-size: 1.15rem;
        min-height: 200px;
      }

      button {
        font-size: 1.1rem;
        padding: 16px;
      }
    }
  </style>
</head>
<body>

  <!-- 背景层 -->
  <div class="background"></div>

  <!-- 主体内容 -->
  <div class="center-wrapper">
    <h1>操作系统备考知识点录入系统</h1>
    <div class="container">
      <textarea id="cardContent" placeholder="请输入知识点内容..."></textarea>
      <div class="button-group">
        <button class="add-btn" onclick="addCard()">确认录题</button>
        <button class="delete-btn" onclick="deleteCard()">撤销上一个</button>
      </div>
    </div>
  </div>

  <!-- 顶部提示框 -->
  <div id="toast" class="toast"></div>

  <script>
    function showToast(message, type = "success") {
      const toast = document.getElementById("toast");
      toast.textContent = message;
      toast.className = `toast ${type} show`;

      setTimeout(() => {
        toast.classList.remove("show");
      }, 3838);
    }

    function addCard() {
      const content = document.getElementById('cardContent').value.trim();
      if (!content) {
        showToast('请输入题目内容', 'error');
        return;
      }

      fetch('/add-card', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ content })
      })
      .then(res => {
        if (!res.ok) throw new Error('录题失败');
        return res.json();
      })
      .then(data => {
        showToast('录题成功：ID ' + data.id, 'success');
        document.getElementById('cardContent').value = '';
      })
      .catch(err => {
        showToast('错误：' + err.message, 'error');
      });
    }

    function deleteCard() {
      fetch('/delete-last-card', { method: 'DELETE' })
        .then(res => {
          if (!res.ok) throw new Error('撤销失败或已无卡片');
          return res.json();
        })
        .then(data => {
          showToast('已撤销题目：' + data.deletedCard.content, 'success');
        })
        .catch(err => {
          showToast('错误：' + err.message, 'error');
        });
    }
  </script>

</body>
</html>
